﻿using PhuLeBooze.Admin.Global;
using PhuLeBooze.UICode;
using PhuLeBussinessObject.Base;
using PhuLeDao.Contact;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Web.Services;

namespace PhuLeBooze.Services
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    [System.Web.Script.Services.ScriptService]
    public class ContactService : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string AddContactMessage(string Name, string Phone, string Email, string Message)
        {
            string output = "";
            try
            {
                Name = Server.HtmlEncode(Name);
                Phone = Server.HtmlEncode(Phone);
                Email = Server.HtmlEncode(Email);
                Message = Server.HtmlEncode(Message);
                CContactDao contactDao = new CContactDao();
                CApplicationMessage result = contactDao.ActionContact(string.Format("<InputValue Name=\"{0}\"  Phone=\"{1}\"  Email=\"{2}\"  Message=\"{3}\"    Action=\"Insert\"/>", Name, Phone, Email, Message));
                CEmail objMail = new CEmail();
                output = new JavaScriptSerializer().Serialize(result);
                if (CConfigSiteEntity.EmailForward == null)
                    CConfigSiteEntity.ReadConfig();
                objMail.SendMail(CConfigSiteEntity.EmailForward, string.Format("Message {0}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff", CultureInfo.InvariantCulture)), string.Format("Name:{0} <br/> Phone:{1}  <br/> Email:{2}  <br/> Message:{3} ", Name, Phone, Email, Message));

            }
            catch (Exception ex)
            {
            }
            return output;
        }
    }
}
